﻿using System.Collections.Generic;
using System.Linq;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;

public static class BsonListHelper
{
    public static List<T> BsonListToObjectList<T>(this List<BsonDocument> documents) where T : class
    {
        var newlist = new List<T>();
        foreach (var d in documents)
        {
            var newD = BsonSerializer.Deserialize<T>(d);
            newlist.Add(newD);
        }

        return newlist;
    }

    public static T BsonListFirst<T>(this List<BsonDocument> documents) where T : class
    {
        var d = BsonSerializer.Deserialize<T>(documents.First());

        return d;
    }
}